<template>
  <div id="app" class="tempMedicine">
    <div class="files-title">
      <h3>体温异常天数统计</h3>
      <p>{{ searchData.stuName }} 在 {{ searchData.semesterName }} 体温异常 <span>{{temperature}} 天</span></p>
    </div>
    <line-bar ref="lineBar"  :chartData="chartData" :YAxis="YAxis" @ok="handleEmit"></line-bar>
    <div class="files-title">
      <h3>服药统计</h3>
      <p>{{ searchData.stuName }} 在 {{ searchData.semesterName }} 服药次数 <span>{{medication}} 次</span></p>
    </div>
    <line-bar ref="lineBar2"  :chartData="chartData2" :YAxis="YAxis2" @ok="handleEmit"></line-bar>
  </div>
</template>
<script>
import { StudengFiles } from '@/utils/skStudentFilesMixin.js'
import LineBar from "../modules/line-bar.vue";
export default {
  name: 'tempMedicine',
  mixins:[StudengFiles],
  data() {
    return {
      url: {
        query: '',
      },
      searchData: {
        semesterId: '',
        classId: '',
        studentId: '',
      },
      dataList:[],
      chartData:[
        {
          legendTitle:"异常天数",
          type:"line",
          color:["#73DD39"]
        }
      ],
      YAxis:[
        {
          name:"天",
          position:"left"
        }
      ],
      chartData2:[
        {
          legendTitle:"服药次数",
          type:"line",
          color:["#F58080"]
        }
      ],
      YAxis2:[
        {
          name:"次",
          position:"left"
        }
      ],
      temperature:0,
      medication:0,
      numList:[]
    }
  },
  components: {
    LineBar
  },
  props:["dataForm","semesterName","className"],
  filters: {},

  computed: {},

  created() {},

  activated() {},


  methods: {
    // /查看单个幼儿数据
    initStudentChart(){
      this.getTemperatureData();
      this.getMedicineData();
    },
    // 体温
    async getTemperatureData(){
      this.url.query = "/health/skTemperatureRecord/getStudentTemperature"
      const params = {
        byType:"month"
      }
      let data = await this.queryData(params);
      let categorys = [],xData = [];
      const monthColumns = this.dataForm.daysColums;
      let arr1 = [];
      this.temperature = 0
      for(let rowIndex = 0; rowIndex < monthColumns.length; rowIndex++){
        const rowString = monthColumns[rowIndex].toString();
        categorys.push(rowString);
        const monthData = data.find(item => item.statisticalDate == rowString);
        if (monthData){
          arr1.push(monthData.abnormalNum)
          this.temperature += monthData.abnormalNum
        } else {
          arr1.push(0)
        }
      }
      xData.push(arr1)
      this.$refs.lineBar.initEChart(categorys,xData)
    },
    // 服药
    async getMedicineData(){
      this.url.query = "/health/skMedicationRecord/getStudentMedicationByMonth"
      let data = await this.queryData();
      let categorys = [],xData = [];
      const monthColumns = this.dataForm.daysColums;
      let arr1 = [];
      this.medication = 0
      for(let rowIndex = 0; rowIndex < monthColumns.length; rowIndex++){
        const rowString = monthColumns[rowIndex].toString();
        categorys.push(rowString);
        const monthData = data.find(item => item.month == rowString);
        if (monthData){
          arr1.push(monthData.medicationNum)
          this.medication += monthData.medicationNum
        } else {
          arr1.push(0)
        }
      }
      xData.push(arr1)
      this.$refs.lineBar2.initEChart(categorys,xData)
    },
    handleEmit(){
      this.numList.push(true);
      if (this.numList.length == 2) {
        this.$emit("ok")
      }
    }
  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
@import url(~@/assets/less/studentFiles.css); 
</style>
